package test1;

import java.util.Arrays;

public class Test3 {
    public static void main(String[] args) {
        int[] nums = new int[]{2, 5, 4, 6, 1, 7};
        int[] arr = shell_sort(nums);
        for (int i : arr) {
            System.out.print(i + " ");
        }
    }

    private static int[] shell_sort(int[] nums) {
        int[] arr = Arrays.copyOf(nums, nums.length);
        int gap = nums.length;
        while (gap > 1) {
            gap /= 2;
            for (int i = 0; i < arr.length - gap; i++) {
                int j = i;
                int tmp = arr[j + gap];
                while (j >= 0 && tmp < arr[j]) {
                    arr[j + gap] = arr[j];
                    j -= gap;
                }
                arr[j + gap] = tmp;
            }
        }
        return arr;
    }
}
